home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / record11.zip / RECORDER.ASM < prev    next >
Assembly Source File  |  1988-05-17  |  22KB  |  746 lines

  1.         Page 60,132
  2. ;----------------------------------------------------------------------
  3. ; RECORDER.ASM - A resident program which counts file operations.
  4. ; Run it once to install and initialize it.  Run it again later to
  5. ; view a list of files which have been accessed.  The table
  6. ; shows how many disk accesses have been made while reading and
  7. ; writing to the file.
  8. ;
  9. ; SYNTAX:   RECORDER  [n] [/R]
  10. ; USE   n to specify the maximum number of files (default=200)
  11. ; Use  /R to reset the file table.
  12. ;----------------------------------------------------------------------
  13. CSEG        SEGMENT
  14.         ASSUME    CS:CSEG,DS:NOTHING
  15.         ORG    100H    ;Beginning for .COM programs
  16. START:        JMP INITIALIZE    ;Initialization code is at end
  17.  
  18. ;-----------------------------------------------------------------------
  19. ; Data area used by this program
  20. ;-----------------------------------------------------------------------
  21. COPYRIGHT    DB    "RECORDER 1.0 (c) 1988 Ziff Communications Co."
  22. PROGRAMMER    DB    13,10,"PC Magazine ",254," Tom Kihlken$",1AH
  23.  
  24. FULL_MESS    DB    "*Table is saturated*$"
  25. OLDINT21    DD    ?    ;Old DOS function interrupt vector
  26. OLDINT13    DD    ?    ;Old BIOS disk I/O interrupt vector
  27. NUM_FILES    DW    200    ;Default size of the table
  28. FILE_TABLE_END    DW    ?
  29. LAST_FILE    DW    ?
  30. LAST_HANDLE    DW    ?
  31.  
  32. ;--to help count spaces-012345678901234567890123456789012345678901-----
  33. HEADER        DB    "   File Name  Total   Read  Write   EXEC$"
  34.  
  35. CURRENT_FILE    DB    11 DUP (?)
  36. CURRENT_HANDLE    DW    ?
  37. FUNCTION_ID    DW    ?
  38. BUSY_FLAG    DB    0
  39. BIOS_IO_COUNT    DW    0    ;Counts disk accesses made by BIOS
  40.  
  41. HANDLE_TABLE    EQU    OFFSET INITIALIZE
  42. FILE_TABLE    EQU    HANDLE_TABLE + NUM_HANDLES * 4
  43. NUM_HANDLES    EQU    30
  44. ENTRY_SIZE    EQU    20
  45.  
  46. ;-----------------------------------------------------------------------
  47. ; Interrupt 13 (Diskette I/O) This routine counts disk sector accesses.
  48. ;-----------------------------------------------------------------------
  49. NEWINT13    PROC    FAR
  50.         ASSUME    DS:NOTHING, ES:NOTHING
  51.         CMP    AH,2        ;Is function lower than 2?
  52.         JB    DONT_COUNT    ;If yes, then ignore it
  53.         CMP    AH,4        ;Is function higher than 4?
  54.         JA    DONT_COUNT    ;If yes, then ignore it
  55.         INC    CS:BIOS_IO_COUNT;Add sectors count to total
  56. DONT_COUNT:
  57.         JMP    CS:OLDINT13    ;Continue with disk interrupt
  58. NEWINT13    ENDP
  59.  
  60. ;-----------------------------------------------------------------------
  61. ; Interrupt 21 (DOS functions)  This routine counts file accesses.
  62. ;-----------------------------------------------------------------------
  63. NEWINT21    PROC    FAR
  64.         ASSUME    DS:NOTHING, ES:NOTHING
  65.  
  66.         PUSHF            ;Save callers flags
  67.         STI            ;Get interrupts back on
  68.         CMP    CS:BUSY_FLAG,0    ;Are we busy now?
  69.         JNE    OLD_DOS        ;If busy, just pass it to DOS
  70.         CMP    AH,4BH        ;Is it the EXEC function?
  71.         JE    EXEC        ;Handle EXEC specially
  72.         CMP    AH,0EH        ;Is it below 0EH?
  73.         JBE    OLD_DOS        ;If yes, ignore it
  74.         CMP    AH,31H        ;Is it TSR function?
  75.         JE    OLD_DOS        ;Dont intercept this call
  76.         CMP    AH,45H        ;Is it above 45H?
  77.         JB    INTERCEPT_IT    ;If yes, then ignore it
  78. OLD_DOS:
  79.         POPF            ;Recover callers flags
  80.         CLI
  81.         JMP    CS:OLDINT21    ;Allow interrupt to proceed
  82. EXEC:
  83.         PUSH    AX        ;Save these registers
  84.         PUSH    BX
  85.         PUSH    CX
  86.         PUSH    SI
  87.         PUSH    DI
  88.         PUSH    DS
  89.         PUSH    ES
  90.         MOV    CS:BUSY_FLAG,1    ;Set the busy flag
  91.         MOV    SI,OFFSET PARSE_STRING ;Point to parse routine
  92.         CALL    ENTER_FILENAME    ;Search file table for the file
  93.         JC    EXEC_CONTINUE
  94.         INC    WORD PTR DS:[SI+12]
  95.         INC    WORD PTR DS:[SI+18]
  96. EXEC_CONTINUE:
  97.         MOV    CS:BUSY_FLAG,0    ;Not busy any more
  98.         POP    ES        ;Restore the registers
  99.         POP    DS
  100.         POP    DI
  101.         POP    SI
  102.         POP    CX
  103.         POP    BX
  104.         POP    AX
  105.         JMP    OLD_DOS
  106. INTERCEPT_IT:
  107.         MOV    BUSY_FLAG,1    ;Ignore any other calls
  108.         MOV    FUNCTION_ID,AX    ;Save the function ident.,
  109.         MOV    BIOS_IO_COUNT,0
  110.         CLI
  111.         CALL    CS:OLDINT21    ;Do the DOS function
  112.         STI            ;Reenable interrupts
  113.         PUSHF            ;Save DOS result flags
  114.         PUSH    AX        ;Save these registers
  115.         PUSH    BX
  116.         PUSH    CX
  117.         PUSH    DX
  118.         PUSH    SI
  119.         PUSH    DI
  120.         PUSH    DS
  121.         PUSH    ES
  122.         JNC    CHECK_FUNCTION    ;If no error, continue
  123.         JMP    POP_RET        ;Otherwise just return
  124. CHECK_FUNCTION:
  125.         MOV    CX,FUNCTION_ID
  126.         SUB    CH,0FH        ;Is it 0Fh?
  127.         JZ    READ_FCB
  128.         DEC    CH        ;Is it 10h?
  129.         JZ    WRITE_FCB
  130.         SUB    CH,4        ;Is it 14h?
  131.         JZ    READ_FCB
  132.         DEC    CH        ;Is it 15h?
  133.         JZ    WRITE_FCB
  134.         DEC    CH        ;Is it 16h?
  135.         JZ    READ_FCB
  136.         SUB    CH,0BH        ;Is it 21h?
  137.         JZ    READ_FCB
  138.         DEC    CH        ;Is it 22h?
  139.         JZ    WRITE_FCB
  140.         DEC    CH        ;Is it 23h?
  141.         JZ    READ_FCB
  142.         SUB    CH,4        ;Is it 27h?
  143.         JZ    READ_FCB
  144.         DEC    CH        ;Is it 28h?
  145.         JZ    WRITE_FCB
  146.         JMP    SHORT NOT_FCB_FUNCTN
  147. READ_FCB:
  148.         MOV    BX,14        ;Index for the read column
  149.         JMP    SHORT INC_FCB_COUNT
  150. WRITE_FCB:
  151.         MOV    BX,16        ;Index for the write column
  152. INC_FCB_COUNT:
  153.         MOV    SI,OFFSET PARSE_FCB
  154.         CALL    ENTER_FILENAME    ;Search file table for the file
  155.         JC    JUMP_POP_RET    ;Quit if file not in table
  156.         MOV    AX,BIOS_IO_COUNT;This many disk operations made
  157.         ADD    CS:[SI][BX],AX    ;Add it to the indexed column
  158.         ADD    CS:[SI+12],AX    ;Add it to the total
  159.         JMP    POP_RET
  160.  
  161. ; If it was not a FCB function, see if it was handle I/O
  162.  
  163. NOT_FCB_FUNCTN:
  164.         SUB    CH,14H        ;Is it 3Ch?
  165.         JE    NEW_HANDLE
  166.         DEC    CH        ;Is it 3Dh?
  167.         JE    NEW_HANDLE
  168.         DEC    CH        ;Is it 3Eh?
  169.         JE    WRITE_HANDLE
  170.         DEC    CH        ;Is it 3Fh?
  171.         JE    READ_HANDLE
  172.         DEC    CH        ;Is it 40h?
  173.         JE    WRITE_HANDLE
  174.         SUB    CH,2        ;Is it 42h?
  175.         JE    READ_HANDLE
  176.         SUB    CH,2        ;Is it 44h?
  177.         JE    IO_CONTROL
  178.         JMP    POP_RET
  179. NEW_HANDLE:
  180.         CMP    AX,5        ;Is it a standard handle?
  181.         JGE    GOOD_HANDLE    ;If not, then record it
  182. JUMP_POP_RET:
  183.         JMP    POP_RET        ;Jump to the return
  184. READ_HANDLE:
  185.         MOV    CX,14        ;Index for the read column
  186.         JMP    SHORT INC_DEV_COUNT
  187. IO_CONTROL:
  188.         CMP    CL,2        ;Is it a read request?
  189.         JE    READ_HANDLE    ;Treat it as a read
  190.         CMP    CL,3        ;Is it a write request?
  191.         JNE    JUMP_POP_RET    ;If not read or write, ignore it
  192. WRITE_HANDLE:
  193.         MOV    CX,16        ;Index for the write column
  194. INC_DEV_COUNT:
  195.         CMP    BX,5        ;Is it a standard handle?
  196.         JB    JUMP_POP_RET    ;If it is, then ignore it
  197.         PUSH    CX        ;Put index on the stack
  198.  
  199. ; Now search the handle table for the handle in BX.
  200.  
  201.         CALL    ADD_PSP        ;Add in the current PSP segment
  202.         MOV    DI,HANDLE_TABLE    ;Point to the handle table
  203.         MOV    CX,NUM_HANDLES    ;Search the entire table
  204. HANDLE_LOOP:
  205.         CMP    BX,CS:[DI]    ;Is it a match?
  206.         JE    HANDLE_MATCH    ;If it is, we've found it
  207.         ADD    DI,4        ;If not, look at next entry
  208.         LOOP    HANDLE_LOOP
  209.         POP    BX        ;Restore the stack
  210.         JMP    SHORT POP_RET    ;Return if handle was not found
  211.  
  212. ; If the handle is being closed, then the entry is deleted.
  213.  
  214. HANDLE_MATCH:
  215.         CMP    BYTE PTR FUNCTION_ID+1,3EH ;Closing this file?
  216.         JNE    NOT_CLOSE
  217.         MOV    WORD PTR CS:[DI],0
  218. NOT_CLOSE:
  219.         MOV    DI,CS:[DI+2]    ;Get pointer to file table entry
  220.         POP    BX        ;Get the index back
  221.         MOV    AX,BIOS_IO_COUNT ;Get the sector count
  222.         ADD    CS:[DI][BX],AX    ;Add it to selected column
  223.         ADD    CS:[DI+12],AX    ;And also to the total column
  224.         JMP    SHORT POP_RET
  225. GOOD_HANDLE:
  226.         MOV    CURRENT_HANDLE,AX    ;Save the handle
  227.         MOV    SI,OFFSET PARSE_STRING  ;Point to parse routine
  228.         CALL    ENTER_FILENAME    ;Add the file to the table
  229.         JC    JUMP_POP_RET    ;If table is full, return
  230.         MOV    AX,BIOS_IO_COUNT;Get number of sectors
  231.         ADD    DS:[SI+12],AX    ;Add to the total column
  232.         ADD    DS:[SI+14],AX    ;Add to the read column
  233.  
  234. ; Now enter this new handle to the handle table
  235.  
  236.         MOV    DI,LAST_HANDLE    ;Get location of last entry
  237.         ADD    DI,4        ;Advance it one position
  238.         CMP    DI,HANDLE_TABLE+NUM_HANDLES*4
  239.         JNE    KEEP_GOING
  240.         MOV    DI,HANDLE_TABLE
  241. KEEP_GOING:
  242.         MOV    LAST_HANDLE,DI      ;Now this is the last handle
  243.         MOV    BX,CURRENT_HANDLE ;Get handle back
  244.         CALL    ADD_PSP        ;Add in the current PSP segment
  245.         MOV    CS:[DI],BX    ;Store the handle
  246.         MOV    CS:[DI+2],SI    ;Store location in file table
  247. POP_RET:
  248.         MOV    CS:BUSY_FLAG,0    ;Not busy any more
  249.         POP    ES        ;Restore all registers
  250.         POP    DS
  251.         POP    DI
  252.         POP    SI
  253.         POP    DX
  254.         POP    CX
  255.         POP    BX
  256.         POP    AX
  257.         POPF            ;Recover DOS result flags
  258.         STI            ;Return with interrupts on
  259.         RET    2        ;Return with these flags
  260. NEWINT21    ENDP
  261.  
  262. ;-----------------------------------------------------------------------
  263. ; ENTER_FILENAME adds the file at DS:DX to the table.
  264. ; It returns with DS:SI pointing to the entry.  If CF=1, then the name
  265. ; was not in the table and no more entries could be added.
  266. ;-----------------------------------------------------------------------
  267.         ASSUME    DS:NOTHING, ES: